package hackathon1212.example;

import java.util.HashMap;
import java.util.Map;

public class FrameworkExampleDAO {

	/*
	 * Follow the singleton pattern
	 */
	private static FrameworkExampleDAO singleton;	
	public synchronized static FrameworkExampleDAO fetchDAO(){
		if(singleton == null){
			singleton = new FrameworkExampleDAO();
		}
		return singleton;
	}
	private FrameworkExampleDAO(){
		init();
	}
	
	//Holds member data to be delt with
	private Map<String, Member> members = new HashMap<String, Member>();
	
	
	/*
	 * Setup test data
	 */
	private void init(){
		addMember("Abi", "171234500001001", "Support", "Abi1982");
		addMember("Brian", "171234500041001", "TwitterAPI", "Brian.N");
		addMember("Carl", "171234500081001", "Hackathon1212", "Classy.Carl");
		addMember("Dave", "171234500091001", "RickStivens", "Dave.G");
		addMember("Ernie", "171234500101001", "ernie_muppet ", "Muppets");
		addMember("Fran", "171234500011001", "49ers", "NLF49ers");
		addMember("George", "171234500051001", "GeorgeTakei", "StarWars1977");
		addMember("Harry", "171234500071001", "Harry_Styles", "oneDirection");
		addMember("Imogen", "171234500111001", "imaginecup", "ImagineCup2012");
		addMember("Jackie", "171234500021001", "kyleandjackieo", "Aus1FM");

	}
	
	/*
	 * Allow member data to be added
	 */
	public void addMember(String name, String cardNo, String twitter, 
			String facebook) {
		final Member m = new Member();
		m.name = name;
		m.cardNo = cardNo;
		final Map<String, String> social = new HashMap<String, String>();
		social.put("twitter", twitter);
		social.put("facebook", facebook);
		m.socialMedia = social;
		members.put(cardNo, m);
	}
	
	/*
	 * Retrieve by card no
	 */
	public Member fetchMemberByCardNo(String cardNo){
		return members.get(cardNo);
	}
	public Member updateTwitter(String cardNo, String twitter) {
		final Member m = fetchMemberByCardNo(cardNo);
		m.socialMedia.put("twitter", twitter);		
		return m;
	}
	
}
